import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../getTypeGoodsPage.dart';

class FSHomeHeaderCategory extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(10),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(14)),
      ),
      child: GridView(
        //GridView是一个可滚动的，2D数组控件。
        shrinkWrap: true, // 收缩，只占用他需要的大小，而不是占满全屏
        physics: NeverScrollableScrollPhysics(),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 5,
          mainAxisSpacing: 10,
          crossAxisSpacing: 3,
          childAspectRatio: 1
        ),
        children: [
          GestureDetector(
            //GestureDetector是手势识别的组件，可以识别点击、双击、长按事件、拖动、缩放等手势。
            child:smicon("二手手机","lib/xianyuApp/imgs/phone.png"),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (_){
                return getTypeGoodsPage(t:1);
              }));
            },
          ),
          GestureDetector(
            child:smicon("二手电脑","lib/xianyuApp/imgs/computer.png"),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (_){
                return getTypeGoodsPage(t:2);
              }));
            },
          ),
          GestureDetector(
            child:smicon("二手图书","lib/xianyuApp/imgs/books.png"),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (_){
                return getTypeGoodsPage(t:4);
              }));
            },
          ),
          GestureDetector(
            child:smicon("母婴玩具","lib/xianyuApp/imgs/game.png"),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (_){
                return getTypeGoodsPage(t:6);
              }));
            },
          ),
          GestureDetector(
            child:smicon("家具家电","lib/xianyuApp/imgs/familytools.png"),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (_){
                return getTypeGoodsPage(t:3);
              }));
            },
          ),
          GestureDetector(
            child:smicon("服饰鞋包","lib/xianyuApp/imgs/beg.png"),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (_){
                return getTypeGoodsPage(t:7);
              }));
            },
          ),
          GestureDetector(
            child:smicon("美妆闲置","lib/xianyuApp/imgs/makeup.png"),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (_){
                return getTypeGoodsPage(t:8);
              }));
            },
          ),
          GestureDetector(
            child:smicon("二手车","lib/xianyuApp/imgs/car.png"),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (_){
                return getTypeGoodsPage(t:9);
              }));
            },
          ),
          GestureDetector(
            child:smicon("学习用品","lib/xianyuApp/imgs/studytools.png"),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (_){
                return getTypeGoodsPage(t:5);
              }));
            },
          ),
          GestureDetector(
            child:smicon("其他类别","lib/xianyuApp/imgs/more.png"),
            onTap: (){
              Navigator.of(context).push(
                  MaterialPageRoute(builder: (BuildContext context) {
                    return getTypeGoodsPage(t:10);
                  }));
              },
          )
        ]
      ),
    );
  }
}

Widget smicon(String name,String path){
  return Container(
    child: Column(
      children: [
        CircleAvatar(
          radius: 20,
          backgroundColor: Colors.white,
          backgroundImage:AssetImage(path),
        ),
        Text(
          name,
          style: TextStyle(
              color: Colors.black,
              fontSize: 14,
              fontWeight: FontWeight.w300
          ),
        ),
      ],
    ),
  );
}